<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


	/**
     * 日期数字转中文
     * 用于日和月、周
     * @static
     * @access public
     * @param integer $number 日期数字
     * @return string
     */
    if (!function_exists('numberToCh')) {
	    function  numberToCh($number) {
	        $number = intval($number);
	        $array  = array('一','二','三','四','五','六','七','八','九','十');
	        $str = '';
	        if($number  ==0)  { $str .= "十" ;}
	        if($number  <  10){
	           $str .= $array[$number-1] ;
	        }
	        elseif($number  <  20  ){
	           $str .= "十".$array[$number-11];
	        }
	        elseif($number  <  30  ){
	           $str .= "二十".$array[$number-21];
	        }
	        else{
	           $str .= "三十".$array[$number-31];
	        }
	        return $str;
	    }
    }


function curlTool($url, $params = null, $method = 'GET') {
	$contents = false;
    if (!in_array($method, array('GET', 'POST'))) {
        error_log(__FUNCTION__ . ": Unknown method '$method'");
        return false;
    }
    if ($method == 'GET') {
        if (is_array($params) && count($params) > 0) {
            if ($params === array_values($params)) {
                error_log(__FUNCTION__ . ": Numerical array recieved for argument '\$params' (assoc array expected)");
                return false;
            }
            else {
                $url .= '?' . http_build_query($params);
            }
        }
        elseif (!is_null($params)) {
            error_log(__FUNCTION__ . ": If you're making a GET request, argument \$params must be null or assoc array.");
            return false;
        }
    }
    $ch = curl_init($url);
    if ($ch !== false) {
        curl_setopt_array($ch, array(
            CURLOPT_HEADER => false,
            CURLOPT_RETURNTRANSFER => true,
        ));
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, true);
            if (is_string($params) || is_array($params)) {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            }
            else {
                error_log(__FUNCTION__ . ": Argument \$params should be an array of parameters or (if you want to send raw data) a string");
                return false;
            }
        }
        $contents = curl_exec($ch);
        curl_close($ch);
    }
    return $contents;

}


/* End of file common_helper.php */
/* Location: ./application/helpers/common_helper.php */